<?php

declare(strict_types=1);

namespace App\Model;


/**
 * @property int $id ID
 * @property int $userid 用户ID
 * @property string $project_id 方案ID
 * @property string $match_id 比赛ID
 * @property string $payment 支付方式 balance-余额
 * @property string $coupon_id 优惠券ID
 * @property int $amount 金额
 * @property int $add_time 下单时间
 * @property-read null|Project $project 
 * @property-read null|Play $match 
 * @property-read null|User $user 
 */
class ProjectOrder extends Model
{
    /**
     * The table associated with the model.
     */
    protected ?string $table = 'project_order';

    /**
     * The attributes that are mass assignable.
     */
    protected array $fillable = ['id', 'userid', 'project_id', 'match_id', 'payment', 'coupon_id', 'amount', 'add_time'];

    /**
     * The attributes that should be cast to native types.
     */
    protected array $casts = ['id' => 'integer', 'userid' => 'integer', 'amount' => 'integer', 'add_time' => 'integer'];

    public function project(){
        return $this->belongsTo(Project::class, 'project_id', 'project_id');
    }

    public function match(){
        return $this->hasOne(Play::class, 'match_id', 'match_id');
    }

    public function user(){
        return $this->hasOne(User::class, 'id', 'userid')->select(['id', 'username', 'nickname', 'role_id', 'avatar']);
    }
}
